import { Input, InputNumber, Select } from '@/components/AntdProxy';
import { CrudFormLayout } from '@/components/Crud';
import {
  ChargeStationSelect,
  CustomerSelect,
  LoadPlaceSelect,
  UnloadPlaceSelect,
} from '@/components/CustomForm';
import {
  CHECK_TYPE_OPTIONS,
  LEVEL_OPTIONS,
  LINE_TYPE_OPTIONS,
  STATE_OPTIONS,
} from '@/constants/enums';
import { REQUIRED } from '@/constants/rules';
import useMaterial from '@/hooks/useMaterial';
import { Button, Form, message } from 'antd';
import styles from './index.less';

const BaseInfo = (props) => {
  const { form, record, request, onOk } = props;
  const { materialTypeOptions } = useMaterial();

  const handleOk = async () => {
    const values = await form.validateFields();
    const params = {
      ...values,
    };
    if (record) {
      params.lineId = record?.lineId;
    }
    await request(params);
    message.success('操作成功');
    onOk?.();
  };

  const handleReset = () => {
    form.resetFields();
  };

  return (
    <div className={styles.baseInfo}>
      <section className={styles.section}>
        <Form form={form} layout="vertical">
          <CrudFormLayout itemMinWidth={250}>
            <Form.Item label="线路名称" name="lineName" rules={[REQUIRED]}>
              <Input />
            </Form.Item>
            <Form.Item label="全称" name="fullName">
              <Input />
            </Form.Item>
            <Form.Item label="装货地" name="loadPlaceId" rules={[REQUIRED]}>
              <LoadPlaceSelect />
            </Form.Item>
            <Form.Item label="卸货地" name="unloadPlaceId" rules={[REQUIRED]}>
              <UnloadPlaceSelect />
            </Form.Item>
            <Form.Item label="其他卸货地" name="unloadPlaceId2">
              <UnloadPlaceSelect />
            </Form.Item>
            <Form.Item label="线路编号" name="lineCode">
              <Input />
            </Form.Item>
            <Form.Item
              label="线路类型"
              name="lineType"
              rules={[REQUIRED]}
              initialValue={0}
            >
              <Select options={LINE_TYPE_OPTIONS} allowClear />
            </Form.Item>
            <Form.Item
              label="物料类型"
              name="type"
              rules={[REQUIRED]}
              initialValue={0}
            >
              <Select options={materialTypeOptions} />
            </Form.Item>
            <Form.Item label="空载里程" name="emptyMileages" initialValue={0}>
              <InputNumber addonAfter="km" />
            </Form.Item>
            <Form.Item label="重载里程" name="heavyMileages" initialValue={0}>
              <InputNumber addonAfter="km" />
            </Form.Item>
            <Form.Item label="空载时长" name="emptyTimes" initialValue={0}>
              <InputNumber addonAfter="分钟" />
            </Form.Item>
            <Form.Item label="重载时长" name="heavyTimes" initialValue={0}>
              <InputNumber addonAfter="分钟" />
            </Form.Item>
            <Form.Item label="报计划站点" name="planStationId">
              <ChargeStationSelect />
            </Form.Item>
            <Form.Item label="单价" name="price" initialValue={0}>
              <InputNumber addonAfter="元/吨" />
            </Form.Item>
            <Form.Item label="司机单价" name="driverPrice" initialValue={0}>
              <InputNumber addonAfter="元/趟" />
            </Form.Item>
            <Form.Item label="级别" name="level">
              <Select options={LEVEL_OPTIONS} />
            </Form.Item>
            <Form.Item label="核算类型" name="checkType" initialValue={0}>
              <Select options={CHECK_TYPE_OPTIONS} />
            </Form.Item>
            <Form.Item label="核算系数" name="checkRatio" initialValue={1}>
              <InputNumber min={0} />
            </Form.Item>
            <Form.Item label="状态" name="state" initialValue={0}>
              <Select options={STATE_OPTIONS} />
            </Form.Item>
            <Form.Item label="装车费" name="loadPrice" initialValue={0}>
              <InputNumber addonAfter="元" />
            </Form.Item>
            <Form.Item label="卸车费" name="unloadPrice" initialValue={0}>
              <InputNumber addonAfter="元" />
            </Form.Item>
            <Form.Item label="信息费" name="infoPrice" initialValue={0}>
              <InputNumber addonAfter="元" />
            </Form.Item>
            <Form.Item label="篷布费" name="tarpaulinPrice" initialValue={0}>
              <InputNumber addonAfter="元" />
            </Form.Item>
            <Form.Item label="过磅费" name="passWeightPrice" initialValue={0}>
              <InputNumber addonAfter="元" />
            </Form.Item>
            <Form.Item label="上车台费" name="upCarPrice" initialValue={0}>
              <InputNumber addonAfter="元" />
            </Form.Item>
            <Form.Item label="下车台费" name="downCarPrice" initialValue={0}>
              <InputNumber addonAfter="元" />
            </Form.Item>
            <Form.Item label="折损系数" name="lossRatio" initialValue={0}>
              <InputNumber />
            </Form.Item>
            <Form.Item
              label="磅单差价"
              name="discrepancyPrice"
              initialValue={0}
            >
              <InputNumber addonAfter="元" />
            </Form.Item>
            <Form.Item label="其他费用" name="otherPrice" initialValue={0}>
              <InputNumber addonAfter="元" />
            </Form.Item>
            <Form.Item label="客户单位" name="customerId">
              <CustomerSelect />
            </Form.Item>
          </CrudFormLayout>
          <Form.Item label="备注" name="remark">
            <Input.TextArea maxLength={150} />
          </Form.Item>
        </Form>
      </section>
      <footer className={styles.footer}>
        <Button type="primary" onClick={handleOk}>
          提交
        </Button>
        <Button onClick={handleReset}>重置</Button>
      </footer>
    </div>
  );
};

export default BaseInfo;
